import pytest
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options


@pytest.fixture(scope="function")
def browser():
    # 配置 Chrome 浏览器（无头模式）
    chrome_options = Options()
    # chrome_options.add_argument("--headless")  # 无界面运行
    chrome_options.add_argument("--disable-gpu")

    # 自动下载并配置 ChromeDriver
    service = Service(ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service, options=chrome_options)

    yield driver  # 返回浏览器对象

    driver.quit()  # 测试结束后退出浏览器